﻿using HslCommunication.Core;
using Modbus_Weigh.Properties;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Modbus_Weigh.Helper
{
    /// <summary>
    /// 原理：通过反射读取和设置类的属性的值，并通过ini格式文件进行存储。
    /// 读写ini文件sunnyui实现，我们不必关心
    /// </summary>
    [ConfigFile("Config\\Setting.ini")]
    public class ConfigHelper : IniConfig<ConfigHelper>
    {
        public string PortName { get; set; }

        public int BaudRate { get; set; }

        public int DataBits { get; set; }

        public Parity Parity { get; set; }

        public StopBits StopBits { get; set; }

        public bool RtsEnable { get; set; }

        public int ReceiveTimeOut { get; set; }

        public byte Station { get; set; }

        public DataFormat DataFormat { get; set; }
        /// <summary>
        /// 地址是不是从0开始
        /// </summary>
        public bool AddressStartWithZero { get; set; }
        /// <summary>
        /// 是否用Crc16校验
        /// </summary>
        public bool Crc16CheckEnable { get; set; }

        /// <summary>
        /// 当第一次运行配置文件不存在时,设置配置默认值，并保存至文件
        /// </summary>
        public override void SetDefault()
        {
            base.SetDefault();
            PortName = "COM19";
            BaudRate = 9600;
            DataBits = 8;
            Parity = Parity.None;
            StopBits = StopBits.One;
            RtsEnable = false;
            ReceiveTimeOut = 5000;
            Station = 1;
            DataFormat = DataFormat.CDAB;
            AddressStartWithZero = true;
            Crc16CheckEnable = true;
        }
    }


}
